/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package univer;
import java.io.FileInputStream;
import org.apache.commons.dbcp.*;
import java.sql.*;
import org.apache.commons.pool.impl.GenericObjectPool;
import java.util.Properties;
import javax.sql.DataSource;


/**
 *
 * @author fairdev
 */
public class ConnManager {

    private DataSource ds = null;
    
    public ConnManager() throws Exception {

        Properties properties = new Properties();
        properties.load(new FileInputStream("database.properties"));
        java.lang.Class.forName(properties.getProperty("driver")).newInstance();
        //Connection conn = DelegatingConnection()
        GenericObjectPool connectionPool = new GenericObjectPool(null);
        ConnectionFactory connFactorty = new DriverManagerConnectionFactory(properties.getProperty("url"),
                properties.getProperty("username"), properties.getProperty("password"));
        
        @SuppressWarnings("unused")
		PoolableConnectionFactory connFactory = new PoolableConnectionFactory(connFactorty, connectionPool,null,null,false,true);
        ds = new PoolingDataSource(connectionPool);
    }

    public Connection getConnection() throws Exception{
        
        Connection conn = ds.getConnection();
        return conn;
    }

}
